let Mock = require("mockjs")
let arrs =  Mock.mock({
    "list|5-15":[
        { 
            image:"@image('200x100','red')",
            name:"@ctitle(3,5)",
            jieshao:"@ctitle(5,7)",
            fenlei:"@ctitle(4)",
            "shoujia|1":["免费","￥0.01"],
            "zhuangtai|1":['学习中','未学习'],
            timer:"@now()"
        }
    ]
  })
Mock.mock("/api/gettable","get",()=>{
    return arrs.list
})
// 删除数据
Mock.mock(/\/api\/delete\/\d/,"delete",(config)=>{
    // let a = arrs.list.filter(i => i.zhuangtai=="未学习")
    let index = config.url.split("/") 
    let id = index[index.length-1] //0 1 2 前边传来的下标
    arrs.list.splice(id,1)
    console.log(arrs.list)
    return arrs.list
})
// 修改数据
Mock.mock(/\/api\/put\/\d/,"put",(config)=>{
    let item = JSON.parse(config.body)
    let index = config.url.split("/")
    let id = index[index.length-1]
    arrs.list.splice(id,1,item)
    return {
        mess:"修改成功"
    }
})
// 增加数据
Mock.mock("/api/post","post",(config)=>{
    let item = JSON.parse(config.body)
    arrs.list.push(item)
    return config.body
})